#include  <iostream>
#include  <cmath>

template<int K>
double _legendre(double x)
{
  double d = 1.0/K;
  return (2.0-d)*x*_legendre<K-1>(x)-(1.0-d)*_legendre<K-2>(x);
}

template<>
double _legendre<0>(double x)
{
  return 1.;
}

template<>
double _legendre<1>(double x)
{
  return x;
}

template double _legendre<0>(double x);
template double _legendre<1>(double x);
template double _legendre<2>(double x);
template double _legendre<3>(double x);
template double _legendre<4>(double x);
template double _legendre<5>(double x);
template double _legendre<6>(double x);
template double _legendre<7>(double x);
template double _legendre<8>(double x);
template double _legendre<9>(double x);
template double _legendre<10>(double x);

template<int K>
double _dlegendre(double x)
{
  return _dlegendre<K-2>(x)-(2.0*K-1.0)*_legendre<K-1>(x);
}

template<>
double _dlegendre<0>(double x)
{
  return 0.;
}

template<>
double _dlegendre<1>(double x)
{
  return 1.0;
}

template double _dlegendre<0>(double x);
template double _dlegendre<1>(double x);
template double _dlegendre<2>(double x);
template double _dlegendre<3>(double x);
template double _dlegendre<4>(double x);
template double _dlegendre<5>(double x);
template double _dlegendre<6>(double x);
template double _dlegendre<7>(double x);
template double _dlegendre<8>(double x);
template double _dlegendre<9>(double x);
template double _dlegendre<10>(double x);


template<int K>
double legendren(double x)
{
  return _legendre<K>(2.0*(x-0.5))*sqrt((2*K+1));
}


template double legendren<0>(double x);
template double legendren<1>(double x);
template double legendren<2>(double x);
template double legendren<3>(double x);
template double legendren<4>(double x);
template double legendren<5>(double x);
template double legendren<6>(double x);
template double legendren<7>(double x);
template double legendren<8>(double x);
template double legendren<9>(double x);
template double legendren<10>(double x);


template<int K>
double dlegendren(double x)
{
  return _dlegendre<K>(2.0*(x-0.5))*sqrt((2*K+1));
}


template double dlegendren<0>(double x);
template double dlegendren<1>(double x);
template double dlegendren<2>(double x);
template double dlegendren<3>(double x);
template double dlegendren<4>(double x);
template double dlegendren<5>(double x);
template double dlegendren<6>(double x);
template double dlegendren<7>(double x);
template double dlegendren<8>(double x);
template double dlegendren<9>(double x);
template double dlegendren<10>(double x);

